package com.enfo.zjabank.service;

import com.enfo.zjabank.dao.BaseDao;
import com.enfo.zjabank.dao.CommentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhoum on 2016/8/4.
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private BaseDao baseDao;
    @Autowired
    private CommentDao commentDao;

    @Override
    public List<Map<String, Object>> listComments(String id) {
        List<Map<String, Object>> list = commentDao.listComments(id);
        return list;
    }

    @Override
    public Map<String, String> publish(String id,String commentText, String inputUser) {
        Map<String,Object> user = baseDao.getUserInfo(inputUser);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        String inputTime = sdf.format(new Date());
        commentDao.publish(id,commentText,inputUser, (String) user.get("full_name"),inputTime);
        Map<String,String> map = new HashMap<>();
        map.put("user",(String) user.get("full_name"));
        map.put("context",commentText);
        map.put("time",inputTime);
        return map;
    }
}
